<template>
	<view class="home-content">
		<image src="../../static/home/home-bg.jpg" mode="widthFix" class="top-img"></image>
		<CustomNav :topBgColor="topBgColor" :color="titleColor" :backColor="'#999'" :isBack="true" :custom="custom"
			:title="'详情'"></CustomNav>
		<view class="detail-block" v-if="type==2">
			<mp-html :content="detail.exposureContent" v-if="detail.exposureContent"></mp-html>
			<view style="text-align: center;" v-else>暂无详情</view>
		</view>
		<view class="detail-block" v-if="type==1">
			<view class="title">{{detail.title}}</view>
			<view class="time">发布时间：{{detail.crtTime}}</view>
			<mp-html :content="detail.content" v-if="detail.content"></mp-html>
			<view style="text-align: center;" v-else>暂无详情</view>
		</view>
	</view>
</template>

<script>
	import {
		getByIdApi,
		getNoticeByIdApi
	} from '@/api/lighthouse.js'
	import {
		getCustomNavData
	} from '@/util/util.js'
	export default {
		data() {
			return {
				custom: null,
				topBgColor: 'rgba(0,0,0,0)',
				titleColor: '#fff',
				detail: {
					exposureContent: '',
					exposureTitle: ''
				},
				type: 0
			}
		},
		methods: {
			getList(id) {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getByIdApi({
					id: this.id
				}).then(data => {
					uni.hideLoading()
					this.detail = data
					console.log(this.detail)
				}).catch(() => {
					uni.hideLoading()
				})
			},
			getDetail(id) {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getNoticeByIdApi({
					id: this.id
				}).then(data => {
					uni.hideLoading()
					this.detail = data
					console.log(this.detail)
				}).catch(() => {
					uni.hideLoading()
				})
			}
		},
		onPageScroll(e) {
			if (e.scrollTop >= 50) {
				this.topBgColor = '#117DFF';
			} else {
				this.topBgColor = 'rgba(0,0,0,0)';
			}
		},
		onLoad(e) {
			this.custom = getCustomNavData();
			this.id = e.id
			this.type = e.type
			if (this.type == 2) {
				this.getList(e.id)
			}
			if (this.type == 1) {
				this.getDetail(e.id)
			}

		}
	}
</script>

<style lang="scss" scoped>
	.home-content {
		width: 100%;

		.top-img {
			width: 100%;
		}

		.detail-block {
			padding: 30rpx;
			display: flex;
			flex-direction: column;
			background: #fff;
			box-shadow: 0 0 10px 0px #e8e8e8;
			border-radius: 30rpx;
			margin: 0rpx auto;
			position: relative;
			min-height: 75vh;
			margin-top: -200rpx;
			line-height: 2;
			font-size: 28rpx;
			text-align: justify;
			text-indent: 56rpx;

			.title {
				text-align: center;
				font-size: 36rpx;
				font-weight: bold;
			}

			.time {
				text-align: center;
				color: #999;
				font-size: 28rpx;
				margin: 20rpx auto;
			}
		}
	}
</style>